package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    //查询所有部门
    @Override
    public List<Dept> queryAllDepts() {
        return deptMapper.queryAllDepts();
    }

    //新增部门
    @Override
    public void insertDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    //修改部门——1.根据id查询
    @Override
    public Dept queryByIdDept(Integer id) {
        return deptMapper.queryByIdDept(id);
    }

    //修改部门——2.修改部门信息
    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }

    //删除部门
    @Override
    public void deleteDept(Integer id) {
        deptMapper.deleteDept(id);
    }
}
